#include "Arbol.h"
#include "QMessageBox"
template <typename T>
Arbol<T>::Arbol()
{
    Raiz=NULL;
}
template <typename T>
Arbol<T>::Arbol(NodoArbol<T> *raiz)
{
    Raiz=raiz;
}
template <typename T>
void Arbol<T>::Deleter(NodoArbol<T> *raiz)
{
    if(raiz==NULL)
        return;
    Deleter(raiz->getHizq());
    Deleter(raiz->getHder());
    delete raiz;
}
/*template <typename T>
Arbol<T>::~Arbol()
{
    Deleter(Raiz);
    Raiz=NULL;
}*/
template <typename T>
QString Arbol<T>::Inorden()
{
    return Inorden(Raiz);
}
template <typename T>
QString Arbol<T>::Preorden()
{
    return Preorden(Raiz);
}
template <typename T>
QString Arbol<T>::Posorden()
{
    return Posorden(Raiz);
}
template <typename T>
QString Arbol<T>::Inorden(NodoArbol<T> *raiz)
{
    QString ret="";
    if(raiz==NULL)
        return ret;
    ret+=Inorden(raiz->getHizq())+" ";
    ret+=QString::number(raiz->getClave())+" ";
    ret+=Inorden(raiz->getHder())+" ";
    return ret;
}
template <typename T>
QString Arbol<T>::Preorden(NodoArbol<T> *raiz)
{
    QString ret="";
    if(raiz==NULL)
        return ret;
    ret+=QString::number(raiz->getClave())+" ";
    ret+=Preorden(raiz->getHizq())+" ";
    ret+=Preorden(raiz->getHder())+" ";
    return ret;
}
template <typename T>
QString Arbol<T>::Posorden(NodoArbol<T> *raiz)
{
    QString ret="";
    if(raiz==NULL)
        return ret;
    ret+=Posorden(raiz->getHizq())+" ";
    ret+=Posorden(raiz->getHder())+" ";
    ret+=QString::number(raiz->getClave())+" ";
    return ret;
}
template <typename T>
NodoArbol<T>* Arbol<T>::getRaiz()
{
    return Raiz;
}
template <typename T>
void Arbol<T>::setRaiz(NodoArbol<T>* raiz)
{
    Raiz=raiz;
}

template <typename T>
bool Arbol<T>::Vacio()
{
    return Raiz==NULL;
}
template <typename T>
bool Arbol<T>::Valido(int clave)
{
    return Valido(clave,Raiz);
}
template <typename T>
T Arbol<T>::Index(int clave)
{
    return Index(clave, Raiz);
}
template <typename T>
bool Arbol<T>::Valido(int clave, NodoArbol<T>* raiz)
{
    bool ret;
    if (raiz==NULL) {
        ret=false;
    } else {
        if (clave==raiz->getClave()) {
            ret=true;
        } else {
            if (clave<raiz->getClave()) {
                ret=Valido(clave,raiz->getHizq());
            } else {
                ret=Valido(clave,raiz->getHder());
            }
        }
    }
    return ret;

}
template <typename T>
T Arbol<T>::Index(int clave, NodoArbol<T> *raiz)
{
    T ret;
    if (clave==raiz->getClave()) {
        ret=raiz->getContenedor();
    } else {
        if (clave<raiz->getClave()) {
            ret=Index(clave,raiz->getHizq());
        } else {
            ret=Index(clave,raiz->getHder());
        }
    }
    return ret;
}

template <typename T>
bool Arbol<T>::Vacio(NodoArbol<T>* raiz)
{
    return raiz==NULL;
}


template class Arbol<hola>;

template class Arbol<Cliente>;
template class Arbol<Registro>;
template class Arbol<Tarjeta>;
template class Arbol<std::string>;
